home *** CD-ROM | disk | FTP | other *** search
- package sunw.demo.juggler;
-
- import java.applet.Applet;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.event.ActionEvent;
- import java.net.URL;
-
- public class Juggler extends Applet implements Runnable {
- private transient Image[] images = new Image[5];
- private transient Thread animationThread;
- private int rate = 125;
- private transient int loop;
- private boolean stopped = true;
-
- public synchronized void start() {
- this.startJuggling();
- }
-
- public synchronized void stop() {
- this.stopJuggling();
- }
-
- public void init() {
- this.images = new Image[5];
-
- for(int var1 = 0; var1 < 5; ++var1) {
- String var2 = "sunw/demo/juggler/Juggler" + var1 + ".gif";
- this.images[var1] = this.loadImage(var2);
- if (this.images[var1] == null) {
- System.err.println("Couldn't load image " + var2);
- return;
- }
- }
-
- }
-
- private Image loadImage(String var1) {
- try {
- URL var2 = new URL(((Applet)this).getCodeBase(), var1);
- Image var3 = ((Applet)this).getImage(var2);
- return var3;
- } catch (Exception var4) {
- return null;
- }
- }
-
- public void paint(Graphics var1) {
- int var2 = this.loop % 4 + 1;
- if (this.stopped) {
- var2 = 0;
- }
-
- if (this.images != null && var2 < this.images.length) {
- Image var3 = this.images[var2];
- if (var3 != null) {
- var1.drawImage(var3, 0, 0, this);
- }
-
- }
- }
-
- public synchronized void setEnabled(boolean var1) {
- super.setEnabled(var1);
- this.notify();
- }
-
- public synchronized void startJuggling() {
- if (this.images == null) {
- this.init();
- }
-
- if (this.animationThread == null) {
- this.animationThread = new Thread(this);
- this.animationThread.start();
- }
-
- this.stopped = false;
- this.notify();
- }
-
- public synchronized void stopJuggling() {
- this.stopped = true;
- this.loop = 0;
- Graphics var1 = ((Component)this).getGraphics();
- if (var1 != null && this.images != null) {
- Image var2 = this.images[0];
- if (var2 != null) {
- var1.drawImage(var2, 0, 0, this);
- }
-
- }
- }
-
- public void startJuggling(ActionEvent var1) {
- this.startJuggling();
- }
-
- public void stopJuggling(ActionEvent var1) {
- this.stopJuggling();
- }
-
- public int getAnimationRate() {
- return this.rate;
- }
-
- public void setAnimationRate(int var1) {
- this.rate = var1;
- }
-
- public Dimension getMinimumSize() {
- return new Dimension(144, 125);
- }
-
- /** @deprecated */
- public Dimension minimumSize() {
- return this.getMinimumSize();
- }
-
- public Dimension getPreferredSize() {
- return this.minimumSize();
- }
-
- /** @deprecated */
- public Dimension preferredSize() {
- return this.getPreferredSize();
- }
-
- public void run() {
- try {
- while(true) {
- synchronized(this){}
-
- try {
- while(this.stopped || !((Component)this).isEnabled()) {
- this.wait();
- }
- } catch (Throwable var5) {
- throw var5;
- }
-
- ++this.loop;
- Graphics var1 = ((Component)this).getGraphics();
- Image var2 = this.images[this.loop % 4 + 1];
- if (var1 != null && var2 != null) {
- var1.drawImage(var2, 0, 0, this);
- }
-
- Thread.sleep((long)this.rate);
- }
- } catch (InterruptedException var6) {
- }
- }
- }
-